package com.sg.service.biz.app.nb;

import cn.hutool.core.bean.BeanUtil;
import com.sg.dto.biz.app.req.*;
import com.sg.dto.biz.app.res.*;
import com.sg.dto.integration.component.GenerateSemanticInstanceReqDto;
import com.sg.dto.integration.component.GenerateSemanticInstanceRespDto;
import com.wicket.okrcomponent.common.annotations.BanAuto;
import com.wicket.okrcomponent.integration.TemplateEngineService;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;

/**
 * @author ： 手工接入方法
 * @version 1.0
 * @since 2022/5/28 15:32
 */
@Service
@BanAuto
public class NbDivineData {
    /**
     * code:invokeTemplateSemantic
     * name:【验证接口】M生成语义实例
     * desc:undefined
     **/
    @Resource
    private TemplateEngineService compClient;

    /**
     * code:invokeTemplateSemantic
     * name:【验证接口】M生成语义实例
     * desc:undefined
     **/
    @BanAuto
    @Trace(operationName = "【验证接口】M生成语义实例")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public GenerateGenerateInstanceResDto generateGenerateInstance(GenerateGenerateInstanceReqDto reqDto) {
        GenerateSemanticInstanceReqDto subReqDto = new GenerateSemanticInstanceReqDto();
        subReqDto.setTemplateSemanticEngineCode(reqDto.getTemplateSemanticEngineCode());
        subReqDto.setSentenceContentParam(reqDto.getTemplateContent() + reqDto.getMetaDataColumnContent());
        GenerateSemanticInstanceRespDto resultData = compClient.generateSemanticInstance(subReqDto).getData();
        GenerateGenerateInstanceResDto retData = new GenerateGenerateInstanceResDto();
        retData.setSentenceContent(resultData.getSentenceContent());
        return retData;
    }

    /**
     * code:invokeTemplateSemantic
     * name:生成验证接口
     * desc:undefined
     **/
    @BanAuto
    @Trace(operationName = "生成验证接口")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public GenerateVerifyInterResDto generateVerifyInter(GenerateVerifyInterReqDto reqDto) {
        return new GenerateVerifyInterResDto();
    }

    /**
     * code:receptionService
     * name:M3-获取接收字段（特殊方法）
     * desc:undefined
     * gen by moon at 8/28/2022, 4:08:03 PM
     **/
    @Trace(operationName = "M3-获取接收字段（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public ImplementDispatchAcceptParametersRespDto implementDispatchAcceptParameters(ImplementDispatchAcceptParametersReqDto reqDto) {
        return BeanUtil.toBean(reqDto, ImplementDispatchAcceptParametersRespDto.class);
    }

    /**
     * code:getFirstDayAfterCycle
     * name:M3获取周期结束第1天(特殊方法）
     * desc:undefined
     * gen by moon at 8/29/2022, 1:03:39 AM
     **/
    @Trace(operationName = "M3获取周期结束第1天(特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public ObtainCycleEndFirstDayRespDto obtainCycleEndFirstDay(ObtainCycleEndFirstDayReqDto reqDto) {
        //往后加一天
        ObtainCycleEndFirstDayRespDto retData = new ObtainCycleEndFirstDayRespDto();
        Calendar c = Calendar.getInstance();
        c.setTime(reqDto.getCycleEndTime());
        c.add(Calendar.DAY_OF_MONTH, 1);
        Date sDate = c.getTime();
        retData.setCycleEndFirstDay(sDate);
        return retData;
    }

    /**
     * code:receptionService
     * name:M3-获取接收字段（特殊方法）
     * desc:undefined
     * gen by moon at 9/9/2022, 8:38:02 PM
     **/
    @Trace(operationName = "M3-获取接收字段（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public ObtainReceiveFieldRespDto obtainReceiveField(ObtainReceiveFieldReqDto reqDto) {
        return BeanUtil.toBean(reqDto, ObtainReceiveFieldRespDto.class);
    }

    /**
     * code:maxOfMultipleNumAddOne
     * name:M3-获取取数据集最大值（特殊方法）
     * desc:undefined
     * gen by moon at 9/19/2022, 2:57:23 PM
     **/
    @Trace(operationName = "M3-获取取数据集最大值（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public ObtainMaxOfCollectionsRespDto obtainMaxOfCollections(ObtainMaxOfCollectionsReqDto reqDto) {
        ObtainMaxOfCollectionsRespDto retData = new ObtainMaxOfCollectionsRespDto();
        Long max = Collections.max(reqDto.getBusAppDocRelaList());
        retData.setOrderNumber(max);
        return new ObtainMaxOfCollectionsRespDto();
    }

    /**
     * code:rowToColumn
     * name:M-数据集转字段(特殊方法）
     * desc:undefined
     * gen by moon at 7/5/2023, 1:28:00 AM
     **/
    @Trace(operationName = "M-数据集转字段(特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public TransitionColumnToRowRespDto transitionColumnToRow(TransitionColumnToRowReqDto reqDto) {
        // TODO ruizhe skai dong ; 7/5/2023, 1:28:00 AM
        return new TransitionColumnToRowRespDto();
    }

    /**
     * code:receptionService
     * name:M3接收内容表主键id
     * desc:undefined
     * gen by moon at 3/27/2024, 8:01:46 PM
     **/
    @Trace(operationName = "M3接收内容表主键id")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public ImplementEightReceivingFieldRespDto implementEightReceivingField(ImplementEightReceivingFieldReqDto reqDto) {
        return BeanUtil.toBean(reqDto, ImplementEightReceivingFieldRespDto.class);
    }
    //手工接入方法
}
